package com.ycq.webssm.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Map;

@Controller
public class ScopeController {



    @PostMapping("/testRequestByServletApi")
    public String testRequestByServletApi(HttpServletRequest request) {
        request.setAttribute("key1", "value1");
        return "success";
    }


    @PostMapping("/testSession")
    public String testSession(HttpSession session) {
        session.setAttribute("key2", "value2");
        return "success";
    }

    @PostMapping("/testModelAndView")
    public ModelAndView testModelAndView() {
        ModelAndView mav = new ModelAndView();
        //处理模型数据 即向请求域request共享数据
        mav.addObject("key1","value1");
        //设置视图名称
        mav.setViewName("success");
        return mav;
    }


    @PostMapping("/testModel")
    public String testModel(Model model) {
        //处理模型数据 即向请求域request共享数据
        model.addAttribute("key1","value1");
        return "success";
    }


    @PostMapping("/testMap")
    public String testMap(Map<String,Object> model) {
        //处理模型数据 即向请求域request共享数据
        model.put("key1","value1");
        return "success";
    }


    @PostMapping("/testModelMap")
    public String testModelMap(ModelMap modelMap) {
        //处理模型数据 即向请求域request共享数据
        modelMap.addAttribute("key1","value1");
        return "success";
    }









}
